package com.abso.sunlight.api;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.dom4j.Element;

/**
 * Lobbyst.
 */
public class Lobbyist {

    /** Matching score. */
    private double score;

    /** Registrant's name. */
    private String registrantName;

    /** Lobbyist's last name. */
    private String lastName;

    /** Lobbyist's first name. */
    private String firstName;

    /** List of filing ids. */
    private List<String> filingIds;

    /**
     * Constructs a new lobbyist.
     * 
     * @param elem
     *            the XML holding filing lobbyist information.
     * @throws SunlightException
     *             if an exception occurred creating the lobbyist.
     */
    public Lobbyist(Element elem) throws SunlightException {
        this.score = SunlightDataUtils.getDouble(elem, "score");
        this.registrantName = SunlightDataUtils.getString(elem, "lobbyist/registrant_name");
        this.lastName = SunlightDataUtils.getString(elem, "lobbyist/lastname");
        this.firstName = SunlightDataUtils.getString(elem, "lobbyist/firstname");
        String ids = SunlightDataUtils.getString(elem, "lobbyist/filings");
        this.filingIds = Arrays.asList(StringUtils.split(ids));
    }

    /**
     * Returns matching score.
     * 
     * @return matching score.
     */
    public double getScore() {
        return score;
    }

    /**
     * Returns registrant's name.
     * 
     * @return registrant's name.
     */
    public String getRegistrantName() {
        return registrantName;
    }

    /**
     * Returns lobbyist's last name.
     * 
     * @return lobbyist's last name.
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Returns lobbyist's first name.
     * 
     * @return lobbyist's first name.
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Returns list of filing ids.
     * 
     * @return list of filing ids.
     */
    public List<String> getFilingIds() {
        return filingIds;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }

}
